home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 2.0 KB | 80 lines | [AMAS/AMAP] |
- // -* ShootBehavior.js *-
- //
- // Name: Shoot behavior
- // Description:
- // Author:
- // Version: $Id: ShootBehavior.js,v 1.11 2000/12/21 15:03:30 consumer Exp $
- //
-
- // Keep an array of the solids using this behavior
- var shootSolids = new Array(1);
-
- function ShootBehavior(solidName, camera, direction, intensity)
- {
- // Member methods of the behavior
- this.start = ShootBehaviorStart;
- this.stop = ShootBehaviorStop;
-
- // Member variables of the behavior
- this.solidName = solidName;
- this.direction = direction;
- this.intensity = intensity * TSSolidGetMass(solidName);
- this.camera = camera;
- }
-
- function ShootBehaviorStart()
- {
- var position = TSSolidGetPosition(this.solidName);
- var dampingID = TSMakeUniqID("DampingForce_" + this.solidName);
- var shootID = TSMakeUniqID("ShootForce_" + this.solidName);
- var shootDir;
-
- if (this.camera == "") {
- shootDir = this.direction;
- }
- else {
- // Calculate the direction of the shoot force
- shootDir = TSMakeStringFromVector(TSVectorNormalize(TSMakeVector(TSCameraGetPosition(this.camera), position)));
- }
-
- TSMakeDampingSolidForce(dampingID, 1.0, 0.5);
- TSAppendChild(this.solidName, dampingID);
-
- TSMakeShootForce(shootID, shootDir, this.intensity, TSMakeStringFromPoint(position));
- TSAppendChild(this.solidName, shootID);
- TSUpdateNode(shootID);
- TSUpdateNode(dampingID);
- TSRemoveNode(shootID);
- TSRemoveNode(dampingID);
- }
-
- function ShootBehaviorStop()
- {
- }
-
- //
- // Event functions
- //
-
- function ShootBehaviorStartEvent(obj, event)
- {
- if (shootSolids[obj] == null) {
- var direction = TSGetExtraParam(event, 'direction');
- var intensity = TSGetExtraParam(event, 'intensity');
- var targetSolid = TSGetExtraParam(event, 'targetSolid');
- var camera = TSGetExtraParam(event, 'camera');
-
- if (targetSolid == "")
- shootSolids[obj] = new ShootBehavior(obj, camera, direction, intensity);
- else
- shootSolids[obj] = new ShootBehavior(targetSolid, camera, direction, intensity);
- }
-
- shootSolids[obj].start();
- }
-
- function ShootBehaviorStopEvent(obj, event)
- {
- shootSolids[obj].stop();
- }
-